import React,{useState,useRef} from 'react'
import { TodolistContext } from './context';


export const Input = () => {
    const [val,setVal]=useState('1234');
    const inpRef=useRef();//! 获取DOM节点
    console.log(inpRef);
    return (
        <div>
            <input ref={inpRef} value={val} onChange={(e)=>{setVal(e.target.value)}} type='text'/>
            <button onClick={()=>{console.log(inpRef.current.value)}}>添加</button>
            <TodolistContext.Consumer>
                {
                    ({addItem})=>{
                        return <button onClick={()=>addItem(val)}>添加</button>
                    }
                }
            </TodolistContext.Consumer>
            
        </div>
    )
}
